package com.wc.AlgoOJ_homework.AlgoOJ_test1.D_象的摆放;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/4 19:56
 * @description http://43.138.190.70:8888/p/695?tid=65e5737f27489dab814f4d03
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 210;
    static int[][] a = new int[N][N];
    static int[][] s1 = new int[N][N];
    static int[][] s2 = new int[N][N];
    static int t, n, m;

    public static void main(String[] args) {
        t = sc.nextInt();
        while (t-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    a[i][j] = sc.nextInt();
                }
            }
            for (int i = 1; i <= m; i++) {
                int x = 1;
                int y = i;
                while (x <= n && y <= m) {
                    s1[x][y] = a[x][y] + s1[x - 1][y - 1];
                    x++;
                    y++;
                }
                x = 1;
                y = i;
                while (x <= n && y >= 1) {
                    s2[x][y] = a[x][y] + s2[x - 1][y + 1];
                    x++;
                    y--;
                }
            }
            for (int j = 2; j <= n; j++) {
                int x = j;
                int y = 1;
                while (x <= n && y <= m) {
                    s1[x][y] = a[x][y] + s1[x - 1][y - 1];
                    x++;
                    y++;
                }
                x = j;
                y = m;
                while (x <= n && y >= 1) {
                    s2[x][y] = a[x][y] + s2[x - 1][y + 1];
                    x++;
                    y--;
                }
            }
            int res = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    int x = i, y = j;
                    int sum = 0;
                    while (x < n && y < m) {
                        x++;
                        y++;
                    }
                    sum += s1[x][y];
                    x = i;
                    y = j;
                    while (x < n && y > 1) {
                        x++;
                        y--;
                    }
                    sum += s2[x][y];
                    sum -= a[i][j];
                    res = Math.max(sum, res);
                }

            }
            out.println(res);
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    s1[i][j] = s2[i][j] = 0;
                }
            }
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}